﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DDD.Core;

using FloatComparer = DDDTest.Helper.FloatComparer;

namespace DDDTest.Core {
    [TestClass]
    public class TestUniformArray {
        [TestMethod]
        public void Test_New1 () {
            var uarry = new UniformArray ();

            Assert.AreEqual (0, uarry.Count);
        }

        /// <summary>
        /// Uniform変数を即値で指定するテスト
        /// </summary>
        [TestMethod]
        public void Test_Set_1 () {
            var uarry = new UniformArray ();
            var mat = new Matrix4x4 ();
            uarry.Add ("Hello", mat);

            Assert.AreEqual (1, uarry.Count);
        }


        /// <summary>
        /// Uniform変数をプロパティで指定するテスト
        /// </summary>
        [TestMethod]
        public void Test_Set_2 () {
            var uarry = new UniformArray ();
            var node = new Node ();
            uarry.Add ("Hello", node, () => node.Alpha);

            Assert.AreEqual (1, uarry.Count);
        }

        [TestMethod]
        public void Test_Get_1 () {
            var uarry = new UniformArray ();
            var mat = new Matrix4x4 ();

            uarry.Add ("Nakajima Hayate", mat);

            var takei = uarry.Get ("Nakajima Hayate");
            Assert.AreEqual ("Nakajima Hayate", takei.Name);
            Assert.AreEqual (mat, takei.Source);
            Assert.AreEqual (null, takei.PropertyName);
        }

        [TestMethod]
        public void Test_Get_2 () {
            var uarry = new UniformArray ();
            var node = new Node ();

            uarry.Add ("Takei Junko", node, () => node.Alpha);

            var takei = uarry.Get ("Takei Junko");
            Assert.AreEqual ("Takei Junko", takei.Name);
            Assert.AreEqual (node, takei.Source);
            Assert.AreEqual ("Alpha", takei.PropertyName);
        }

        [TestMethod]
        public void Test_Indexer () {
            var uarry = new UniformArray ();
            var node = new Node ();

            uarry.Add ("Yokokawa Kazumi", node, () => node.Alpha);

            var kazumi = uarry["Yokokawa Kazumi"];
            Assert.AreEqual ("Yokokawa Kazumi", kazumi.Name);
            Assert.AreEqual (node, kazumi.Source);
            Assert.AreEqual ("Alpha", kazumi.PropertyName);
        }

        [TestMethod]
        public void Test_Remove () {
            var uarry = new UniformArray ();
            var node = new Node ();

            uarry.Add ("Wakamoto Tetsuko", node, () => node.Alpha);
            uarry.Remove ("Wakamoto Tetsuko");

            Assert.AreEqual (0, uarry.Count);
        }

        [TestMethod]
        public void Test_Enumerator () {
            var uarry = new UniformArray ();
            var tetsuko = new Node ();
            var kazumi = new Node ();
            var takei = new Node ();
            tetsuko.Alpha = 0.1f;
            kazumi.Alpha = 0.2f;
            takei.Alpha = 0.4f;

            uarry.Add ("Wakamoto Tetsuko", tetsuko, () => tetsuko.Alpha);
            uarry.Add ("Yokokawa Kazumi", kazumi, () => kazumi.Alpha);
            uarry.Add ("Takei Junko", takei, () => takei.Alpha);

            var sum = uarry.Sum (x => 1);

            Assert.AreEqual (3, sum);
        }

    }
}
